package test02;

/**
 * @author zhu
 * @date 2024-03-21
 */
public class Account {
    /**
     * 用户名
     */
    private String userName;
    /**
     * 余额
     */
    private double money;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public Account() {
    }

    public Account(String userName, double money) {
        this.userName = userName;
        this.money = money;
    }
    public synchronized void TakeMoney(String userName,double money){
        System.out.print(userName + "取" + money + "元");

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        if (this.money > money){
            this.money = this.money - money;
            System.out.println("，余额剩余" + this.money + "元");
            return;
        }

        System.out.println("，余额不足，余额为" + this.money + "元");
    }
}
